$(function () {
    //全选

    $('.Btn-All').click(function () {
        var aCheckbox=$('.ccc');
        for(var i=0;i<aCheckbox.length;i++){
            aCheckbox[i].checked=true;
        }
        //删除
    });
    $('.Btn-AllDel').click(function () {
        var aCheckbox=$('.ccc');
        for(var i=0;i<aCheckbox.length;i++){
            if (aCheckbox[i].checked){
                $('.ccc').parents('tr').remove()
            }
        }
    });
    //全不选
    $('.Btn-No').click(function () {
        var aCheckbox=$('.ccc');
        for(var i=0;i<aCheckbox.length;i++){
            aCheckbox[i].checked=false;
        }
    });
    //考勤异常
    $('.abnormal').click(function () {
        $('#Mask').show();
        $('#Mask1').show();
        $('#Mask').append($('#Mask1'));

    });
    //关掉弹框
    $('.cancel').click(function () {
        $('#Mask').hide();
        $('#Mask1').hide();
        $('#Mask2').hide();
        $('#Mask3').hide();
        $('#Mask4').hide();
    });

    //详情
    $('.details').click(function () {
        $('#Mask').show();
        $('#Mask3').show();
    });


});

let num=0;
//表单
//setInterval(show,1000);
var a=`<input type="checkbox" name="checkbox" title="发呆" lay-skin="primary" class="ccc">`;
var s=`  <button class="btn btn-default btn-xs details" data-aaa="A" type="button"> <span class="glyphicon glyphicon-star" aria-hidden="true"></span>详情</button>
  <button class="btn btn-default btn-xs edit" data-aaa="A" type="button"> <span class="glyphicon glyphicon-edit" aria-hidden="true"></span>编辑</button>
  <button class="btn btn-default btn-xs remove" data-aaa="A" type="button"> <span class="glyphicon glyphicon-remove-sign" aria-hidden="true"></span>删除</button> `;
var n=0;
var data=[{
    Radio:a,
    Num:n,
    JOb:2111,
    Name:'ccc',
    Gender:'女',
    Post:'老大',
    Time:23,
    Late:12,
    Leave:2,
    Absen:1,
    Fun:s
}, {
    Radio:a,
    Num:1,
    JOb:'0001',
    Name:'xxx',
    Gender:'女',
    Post:'老大',
    Time:23,
    Late:12,
    Leave:2,
    Absen:1,
    Fun:s
},{
    Radio:a,
    Num:n,
    JOb:'0002',
    Name:'xxx',
    Gender:'女',
    Post:'老大',
    Time:23,
    Late:12,
    Leave:2,
    Absen:1,
    Fun:s
},{
    Radio:a,
    Num:n,
    JOb:'0003',
    Name:'xxx',
    Gender:'女',
    Post:'老大',
    Time:23,
    Late:12,
    Leave:2,
    Absen:1,
    Fun:s
},{
    Radio:a,
    Num:n,
    JOb:'0004',
    Name:'是对的',
    Gender:'女',
    Post:'扫地',
    Time:23,
    Late:12,
    Leave:10,
    Absen:1,
    Fun:s
}
];
var oT=document.querySelector('tbody');
function show() {
    for(var i=0;i<data.length;i++){
        n++;
        var oTr=document.createElement('tr');
        oTr.innerHTML=` <th class="th-last">${data[i].Radio}</th>
            <td>${n}</td>
            <td>${data[i].JOb}</td>
            <td>${data[i].Name}</td>
            <td>${data[i].Gender}</td>
            <td>${data[i].Post}</td>
            <td>${data[i].Time}</td>
            <td>${data[i].Late}</td>
            <td>${data[i].Leave}</td>
            <td>${data[i].Absen}</td>
            <td>${data[i].Fun}</td>`;
        oT.appendChild(oTr);
    }
}
show();

//添加联系人
var arr=[];
$('.two-1').click(function () {
    $('#Mask').show();
    $('#Mask2').show();
    $('#Mask').append($('#Mask2'));

});
//添加
$('.ok').click(function () {
    var oB2=$('.b2').val();
    var oB3=$('.b3').val();
    var oB1=$('.b1').val();
    var oB4=$('.b4').val();
    var oB5=$('.b5').val();
    var oB6=$('.b6').val();
    var oB7=$('.b7').val();
    var oB8=$('.b8').val();
    /*console.log(oB2)*/
    data=[];

    var c={
        Radio:'&nbsp;&nbsp;'+a,
        Num:n,
        JOb:oB1,
        Name:oB2,
        Gender:oB3,
        Post:oB6,
        Time:0,
        Late:0,
        Leave:0,
        Absen:1,
        Fun:s
    };
    //var ss=JSON.stringify(s);

    data.push(c);
    $('#Mask').hide();
    $('input').val('');
    show();
});
$('.no').click(function () {
    $('#Mask').hide();
    $('input').val('');
});

//删除
var oBtn=$('.remove');
var oTr=$('tr');
var oTable=$('.tab');

oTable.on('click','.remove',function () {
    $(this).parents('tr').remove();
});

//编辑
$('.edit').click(function () {
    $('#Mask').show();
    $('#Mask4').show();
    //确认
    num=$(this).parent().parent().index();

});
$('.okkk').click(function (e) {

    $('#Mask4 .form-control').each(function (i,e) {
        arr.push($(e).val());
    });
    data[num-1].JOb=arr[1];
    data[num-1].Name=arr[2];
    data[num-1].Gender=arr[3];
    data[num-1].Post=arr[4];
    data[num-1].Time=arr[5];
    data[num-1].Late=arr[6];
    data[num-1].Leave=arr[7];
    data[num-1].Absen=arr[8];

    let nowTr=$('.table-striped tr').eq(num);
    nowTr.find('td').eq(1).text(arr[0]);
    nowTr.find('td').eq(2).text(arr[1]);
    nowTr.find('td').eq(3).text(arr[2]);
    nowTr.find('td').eq(4).text(arr[4]);
    nowTr.find('td').eq(5).text(arr[5]);
    nowTr.find('td').eq(6).text(arr[6]);
    nowTr.find('td').eq(7).text(arr[7]);
    nowTr.find('td').eq(8).text(arr[8]);

     $('#Mask').hide();
     $('#Mask4').hide();
});
//取消
$('.no').click(function () {
    $('#Mask4').hide();
});
//页面搜索
$(".soso").click(function(){
    var oS = $(".so").val();
    console.log(oS);
    if(oS.length==0){
        alert("请输入内容");
    }else if($("table tr td:contains('"+oS+"')").length==0){
        alert("找不到数据");
    }else{
        $(".table tr:not(:first)").hide();
        $(".table tr:contains('"+oS+"')").show().find("input").prop("checked",true);
    }

});